package com.learning.javaweb_springboot_jwt.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;


//设置放行路径

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
                .csrf(csrf -> csrf.disable())  // 禁用CSRF保护
                .authorizeHttpRequests(authorize -> authorize
                        .requestMatchers("/login", "/register","/users").permitAll()  // 允许不需要认证的请求
                        .anyRequest().authenticated()  // 其它请求需要认证
                );

        return http.build();
    }
}

